package android07.newtop.holder;

import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import android07.newtop.R;
import android07.newtop.model.bean.WeatherInfoBean;
import android07.newtop.view.Themometer;


/**

 *
 */
public class NowWeatherViewHolder extends BaseViewHolder<WeatherInfoBean.ResultBean.DataBean.RealtimeBean> {


    private static final String TAG = NowWeatherViewHolder.class.getSimpleName();
    private ImageView weathericon;
    private Themometer tempflu;
    private TextView tempmax;
    private TextView tempmin;
    private LinearLayout templayout;
    private LinearLayout lineartemp;
    private TextView temppm;
    private TextView tempquality;
    private android.support.v7.widget.CardView cardView;
    private TextView windfx;
    private TextView windgrade,weather_wu;

    public NowWeatherViewHolder(ViewGroup parent) {
        super(parent, R.layout.item_temperature);

        //此行代码是为了 一键findviewby而书写  非常爽！！！！
        //View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_temperature, null);
        this.cardView = (CardView) itemView.findViewById(R.id.cardView);
        this.windgrade = (TextView) itemView.findViewById(R.id.wind_grade);
        this.windfx = (TextView) itemView.findViewById(R.id.wind_fx);
        this.weather_wu = (TextView) itemView.findViewById(R.id.weather_wu);
        this.lineartemp = (LinearLayout) itemView.findViewById(R.id.linear_temp);
        this.templayout = (LinearLayout) itemView.findViewById(R.id.temp_layout);
        this.tempmin = (TextView) itemView.findViewById(R.id.temp_min);
        this.tempmax = (TextView) itemView.findViewById(R.id.temp_max);
        this.tempflu = (Themometer) itemView.findViewById(R.id.temp_flu);
        this.weathericon = (ImageView) itemView.findViewById(R.id.weather_icon);


    }


    /**
     * 这里是数据设置的方法，非常简单，面向对象编程
     * <p>
     * 当数据成功获取，并且填充到Adpter这里可以设置每个item的数据
     *
     * @param data
     */
    @Override
    public void setData(WeatherInfoBean.ResultBean.DataBean.RealtimeBean data) {
        super.setData(data);

        try {
            //自定义控件设置温度值
            tempflu.setTemperature(Float.valueOf(data.getWeather().getTemperature()));
//            tempflu.setText(String.format("%s℃", data.getWeather().getTemperature()));
//                tempMax.setText(
//                    String.format("↑ %s ℃", weather.dailyForecast.get(0).tmp.max));
//                tempMin.setText(
//                    String.format("↓ %s ℃", weather.dailyForecast.get(0).tmp.min));

//                tempPm.setText(String.format("PM2.5: %s μg/m³", Util.safeText(weather.aqi.city.pm25)));
            windgrade.setText(String.format("风速: %s ", data.getWind().getPower()));
            windfx.setText(String.format("风向: %s ", data.getWind().getDirect()));
            weather_wu.setText(String.format("天气: %s ", data.getWeather().getInfo()));
//                tempQuality.setText(Util.safeText("空气质量： ", weather.aqi.city.qlty));
//                ImageLoader.load(itemView.getContext(),
//                    SharedPreferenceUtil.getInstance().getInt(weather.now.cond.txt, R.mipmap.none),
//                    weatherIcon);
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }

    }
}
